﻿var hg_time = null;
var lgjz = "";
var ltplj = "";
var bs = 0;
function kaishihuoqu()
{
    var huidiao = document.getElementById("huidiao");
	var xhr = new XMLHttpRequest();
	xhr.open("GET", "sz/hd.php?sjh=" + sjh + "&r="+Math.random().toString(), true);
	xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");
	xhr.onreadystatechange = function(){
 	   var XMLHttpReq = xhr;
  	  if (XMLHttpReq.readyState == 4) {
   	     if (XMLHttpReq.status == 200) {
    	        var text = XMLHttpReq.responseText;
                strs=text.split("|Anters_fg|");
                if(strs.length >= 1)
                {
                    var gjzzs = "关键字：" + strs[0];
                    if(lgjz != strs[0])
                    {
                        
                        huidiao.innerHTML = gjzzs;
                        lgjz = strs[0];
                    }
		              
                    if(strs.length >= 2 && strs[1] != ltplj)
                    {
                        huidiao.innerHTML = gjzzs + "<br /><a href='getLJ.php?sjh="+sjh+"' target='_blank'>进入图片</a><br /><iframe width = '400px' height = '400px' src='"+strs[1]+"'></iframe>";
                        ltplj = strs[1];
                    }
                }
                if(hg_time)clearTimeout(hg_time);
                hg_time = setTimeout("kaishihuoqu();",3500);
    	    }
   	 }	
	};
	xhr.send();
    hg_time = setTimeout("kaishihuoqu();",6000);
    
}
function kaishi(a)
{
    alert("123");
    
    if(a.innerHTML=="停止")
    {
        if(hg_time)clearTimeout(hg_time);
        a.innerHTML="自动跟踪";
        return;
    }
    a.innerHTML="停止";
    var huidiao = document.getElementById("huidiao");
    huidiao.style.border="1px solid red";
    kaishihuoqu();
}
window.onload=function(){
    //用户名检测
    var aInput=document.getElementsByTagName('input');
	var aI=document.getElementsByTagName('i')[0];
	var oUser=aInput[0];
	var oPwd=aInput[1];
    oUser.onfocus=function(){
        aI.innerHTML='';
        oUser.removeAttribute("placeholder");
    }
    oUser.onblur=function(){
        if(this.value.length > 20){
            aI.innerHTML='<br />手机号/用户名 不正确<br />';
        }else if(this.value==""){
            aI.innerHTML='<br />手机号/用户名 不可为空';
        }
    }
    
    //密码检测
    oPwd.onfocus=function(){
        if(oUser.value==""){
            aI.innerHTML='<br />手机号/用户名 不可为空';
        }
        oPwd.removeAttribute("placeholder");
    }
    oPwd.onblur=function(){
        if(this.value==""){
            aI.innerHTML='<br />密码不可为空';
        }
    }
    
    
}


function TryLogin()
{
  	var aInput=document.getElementsByTagName('input');
	var aI=document.getElementsByTagName('i')[0];
	var oUser=aInput[0];
	var oPwd=aInput[1];
    var yzmsr = document.getElementById('yzmsr');
    var sjh = oUser.value;
    if(bs == 0){
        bs = 1;
        aI.style.color = "red";
    }
    else {
        bs = 0;
        aI.style.color = "white";
    }
    if(oUser.value == ""){
        aI.innerHTML='<br />手机号/用户名 不可为空';
        return false;
    }else if(oUser.value.length > 20){
        aI.innerHTML='<br />手机号/用户名 不正确<br />';
        return false;
    }else if(oPwd.value == ""){
        aI.innerHTML='<br />密码不可为空';
        oPwd.focus();
        return false;
    }
    aI.innerHTML='登陆中……';
	var postData = {
	    "sjh": oUser.value,
	    "pw": oPwd.value,
        "yzm": yzmsr.value
		};
        
	postData = (function(obj){ // 转成post需要的字符串.
	    var str = "";
 
	    for(var prop in obj){
     	  	 str += prop + "=" + obj[prop] + "&"
    	}
   	 return str;
	})(postData);
 	
	var xhr = new XMLHttpRequest();
 
	xhr.open("POST", "login.php?m="+Math.random().toString(), true);
	xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");
	xhr.onreadystatechange = function(){
 	   var XMLHttpReq = xhr;
  	  if (XMLHttpReq.readyState == 4) {
   	     if (XMLHttpReq.status == 200) {
    	        var text = XMLHttpReq.responseText;
		          if(parseInt(text) == 1 || parseInt(text) == 2)
		          {
			         window.location.href = "login.php?tz=1";
			         return false;
		          }else if(text == 'dxyz'){
		              text = '';
                      $.get('dxyz.php?sjh='+sjh,function(data) {
		                  if(parseInt(data) == -1)aI.innerHTML = "<br />" + '登录异常，短信发送异常';
                          else aI.innerHTML = "<br />" + "登录异常，请查收短信获取验证码";
                          /*else{
                             var content = '002验证码：' + data + '，3分钟内输入有效。如非本人操作请忽略。';      
                             alert(content);     
                              content = encodeURI(content);
        		              $.post('http://api01.monyun.cn:7901/sms/v2/std/',{
        		                  'apikey':'ae3cf70214b0a2a414489463c4e96075',
                                  'mobile':sjh,
                                  'content':content
                                  },function(result) {
                                        alert(result);
                                        if(parseInt(result) != 0)aI.innerHTML = "<br />" + '登录异常，短信发送异常';
                                        else aI.innerHTML = "<br />" + "登录异常，请查收短信获取验证码";
                                  });
        		                  
                              
                          }*/
                      });
		              var yzm = document.getElementById('yzm');
                      yzm.style.display = 'block';
                      yzmsr.focus();
                      
		          }else aI.innerHTML = "<br />" + text;
    	    }
   	 }	
	};
	xhr.send(postData);
	return false;
}